package com.itheima.reggie.mapper;

import com.itheima.reggie.entity.AddressBook;
import com.itheima.reggie.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    @Insert("INSERT INTO address_book VALUES (null,#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},0,#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    void save(AddressBook addressBook);

    @Select("SELECT * FROM address_book WHERE user_id = #{userId} ORDER BY update_time desc")
    List<AddressBook> list(Long userId);

    @Select("SELECT * FROM address_book WHERE id = #{id};")
    AddressBook findById(Long id);


    void update(AddressBook addressBook);

    @Update("UPDATE address_book set is_default = 0 WHERE user_id =#{userId}")
    void removeDefaultAddress(Long userId);

    @Update("update address_book set is_default=1 where id=#{id}")
    void updateDefaultAddress(AddressBook addressBook);

    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBook getDefaultAddress(Long userId);

    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long addressBookId);

    @Delete("DELETE FROM address_book WHERE id = #{id};")
    void deleteById(Long ids);


    String sql = "UPDATE 表名 SET 字段名=新值 WHERE 条件;";
}
